<div id="required_fields_message"><?php echo $this->lang->line('common_fields_required_message'); ?></div>
<ul id="error_message_box"></ul>
<?php
echo form_open('tax_configs/save/'.$tax_info->tax_id,array('id'=>'tax_form'));
?>
<fieldset id="item_basic_info">
<legend><?php echo $this->lang->line("tax_basic_information"); ?></legend>

<div class="field_row clearfix">	
<?php echo form_label($this->lang->line('tax_name').':', 'name',array('class'=>'required wide')); ?>
	<div class='form_field'>
	<?php echo form_input(array(
		'name'=>'name',
		'id'=>'name',
		'value'=>$tax_info->name)
	);?>
	</div>
</div>


<fieldset id="item_basic_info">
<legend><?php echo $this->lang->line("tax_components"); ?></legend>

<div id="tax_components_div" >

<?php 
if($tax_componets->num_rows()==0)
{?>

<div class="field_row clearfix">	
<?php echo form_label($this->lang->line('common_first').':', 'tax_percent_1',array('class'=>'wide')); ?>
	<div class='form_field'>
	<?php echo form_hidden('order[]',1);?>
	</div>
	<div class='form_field'>
	Amount
	<?php echo form_input(array(
		'name'=>'amount[]',
		'id'=>'amount',
		'size'=>'8',
		'value'=> '0')
	);?>
	</div>
	<div class='form_field'>
	Percent
	<?php echo form_input(array(
		'name'=>'percent_value[]',
		'id'=>'percent_value',
		'size'=>'3',
		'value'=> '0'));?>
	%
	</div>
</div>


<div id="tax_inner"></div>

<div class="field_row clearfix">	
<?php echo form_label($this->lang->line('common_exceeding').':', 'exceeding',array('class'=>'wide')); ?>
	<div class='form_field'>
	
	<?php echo form_input(array(
		'name'=>'exceeding',
		'id'=>'exceeding',
		'size'=>'8',
		'value'=>'0')
	);?>
	%
	</div>
</div>

<div class="field_row clearfix">	
	<div class='form_field'>
	<?php echo form_hidden('theValue',0);?>
	</div>
</div>
<?php
}
else
{
	
}

echo form_button(array(
	'name'=>'more_btn',
	'id'=>'more_btn',
	'onclick'=>'add_field();',
	'class'=>'submit_button float_right'),$this->lang->line('common_add_more')
);

echo form_button(array(
	'name'=>'remove_btn',
	'id'=>'remove_btn',
	'onclick'=>'remove_field();',
	'class'=>'submit_button float_right'),$this->lang->line('common_remove')
);
?>

</fieldset>


<?php
echo form_submit(array(
	'name'=>'submit',
	'id'=>'submit',
	'value'=>$this->lang->line('common_submit'),
	'class'=>'submit_button float_right')
);
?>
</fieldset>
<?php 
echo form_close();
?>
<script type='text/javascript'>

//validation and submit handling
$(document).ready(function()
{	
	$('#tax_form').validate({
		submitHandler:function(form)
		{
			$(form).ajaxSubmit({
			success:function(response)
			{
				tb_remove();
				post_item_form_submit(response);
			},
			dataType:'json'
		});

		},
		errorLabelContainer: "#error_message_box",
 		wrapper: "li",
		rules: 
		{
			name:"required"
   		},
		messages: 
		{
			name:"<?php echo $this->lang->line('tax_name_required'); ?>"
		}
	});
});

	
	function add_field()
	{	
		var inner_DIV = document.getElementById('tax_inner');
		var numi = document.getElementById('theValue');
		var num = (numi.value -1)+ 2;
		numi.value = num;
		var order_value = num + 1;
		var newdiv = document.createElement('div');
		var divIdName = 'my'+num+'Div';
		newdiv.setAttribute('id',divIdName);
		newdiv.setAttribute('name',divIdName);
		newdiv.setAttribute('class','formw');
		newdiv.innerHTML = '<div class="field_row clearfix"><label for="" class="wide">Next :</label><div class=\'form_field\'><input id=\'order[]\' value='+order_value+' name=\'order[]\' type=\'hidden\'></div>&nbsp;<div class=\'form_field\'>Amount<input id=\'amount[]\' name=\'amount[]\' type=\'text\' size=\'8\' value=\'0\'></div>&nbsp;<div class=\'form_field\'>Percent<input id=\'percent_value[]\' name=\'percent_value[]\' type=\'text\' size=\'3\' value=\'0\'>%</div></div>';
		inner_DIV.appendChild(newdiv);
	}
	
	function remove_field()
	{
		var numi = document.getElementById('theValue');
		var divIdName = 'my'+numi.value+'Div';
		
		var num = (numi.value -1);
		numi.value = num;
		
		var d = document.getElementById('tax_inner');
		var olddiv = document.getElementById(divIdName);
		d.removeChild(olddiv);
	}
</script>